//
//  PictureView.m
//  TheRoadAD
//
//  Created by baixue on 16/8/11.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "PictureView.h"
static int i;

#define  imageH  image.size.height * Screen_Width/image.size.width
@implementation PictureView



-(void)layoutSubviews{
    [super layoutSubviews];
    

 
    [self setUpPicture];
    [self setBottomView];
    
}

//设置图片
-(void)setUpPicture{
    
//    NSArray *arr = @[@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg",@"6.jpg",@"7.jpg",@"8.jpg",@"9.jpg"];
    _scrollerView.delegate = self;
    _scrollerView.contentSize = CGSizeMake(Screen_Width * _imageNameArr.count, 0);
    _scrollerView.bounces = NO;
    
    
    for ( i = 0; i < _imageNameArr.count; i++) {
        
        UIImage *image = [UIImage imageNamed:_imageNameArr[i]];
        UIImageView *picture = [[UIImageView alloc] init];
        
        //如果图片宽大于屏幕宽 设置imageView的宽度为屏幕宽  
        if (image.size.width > Screen_Width) {
            picture.frame = CGRectMake(Screen_Width *i, _scrollerView.size.height/2 - imageH/2, Screen_Width, imageH);
        }
        
        [_scrollerView addSubview:picture];
        picture.image = [UIImage imageNamed:_imageNameArr[i]];

    }
    
 
    

}
//点击分享
- (IBAction)share:(id)sender {
    _NAVBLOCK(101);
}
//点击返回
- (IBAction)back:(id)sender {
    _NAVBLOCK(102);
}

//根据scrollerView的偏移量来设置页数
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger index = _scrollerView.contentOffset.x/Screen_Width;
    _pagePicture.text = [NSString stringWithFormat:@"%d/%d",index+1,_imageNameArr.count];
//    _bottomScrollerView.contentOffset = CGPointMake(110 * index, 0);
    

}


-(void)setBottomView{
    _bottomScrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, (_backView.frame.size.height - 60) /2, Screen_Width, 60)];
    [_backView addSubview:_bottomScrollerView];
    
    _bottomScrollerView.contentSize = CGSizeMake(100 * _imageNameArr.count+10, 0);
    _bottomScrollerView.bounces = NO;
    
    
    for ( i = 0; i < _imageNameArr.count; i++) {
        
        UIImageView *picture = [[UIImageView alloc] init];
        picture.frame = CGRectMake((100 * i) + 10, 0, 90, 60);
        [_bottomScrollerView addSubview:picture];
        picture.image = [UIImage imageNamed:_imageNameArr[i]];
        
    }
    
}

@end
